# coding=utf-8
from flask import g
from flask_restful import Resource
from flask_restful.reqparse import RequestParser
from comment.modules.user import User
from comment.modules.expected_return import Expected_return
from financial.resorces.transaction.serializer import ExpectedReturnPaginateSerializer

class ExpectedReturnResource(Resource):
    '''查询当前登录用户所有的预期收益列表'''

    def get(self):
        rp = RequestParser()

        rp.add_argument('curPage') #当前页
        rp.add_argument('perPage') #每页数量

        args = rp.parse_args()

        cur_page = args.curPage
        per_page = args.perPage

        uid = g.user_id
        # user = User.query.filter(User == uid).first()

        #查询当前登录用户所有的预期收益列表
        return_list = Expected_return.query.filter(Expected_return.userId  == uid)
        return_list = return_list.paginate(int(cur_page),int(per_page),error_out=False)

        data = ExpectedReturnPaginateSerializer(return_list).to_dict()

        return {
            'msg':'success',
            'data':data
        }









